Skip to content

Conversation

anannya03
Copy link
Member

Description

Please add an informative description that covers that changes made by the pull request and link all relevant issues.

If an SDK is being regenerated based on a new swagger spec, a link to the pull request containing these swagger spec changes has been included above.

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Enables support for a custom token proxy (including SNI and custom CA trust) for WorkloadIdentityCredential.

  • Adds proxy configuration parsing and validation via environment variables.
  • Introduces a custom HttpClient/HttpResponse pair to route token requests through the proxy with optional CA override and SNI.
  • Adds an SNI-capable SSLSocketFactory wrapper.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
IdentitySslUtil.java Adds SNI-supporting SSLSocketFactory wrapper for custom proxy connections.
ProxyConfig.java Introduces immutable holder for token proxy parameters (URL, SNI, CA info).
CustomTokenProxyHttpResponse.java Implements HttpResponse abstraction over HttpURLConnection for proxy responses.
CustomTokenProxyHttpClient.java Implements HttpClient that rewrites token requests, applies custom trust material and optional SNI.
CustomTokenProxyConfiguration.java Parses and validates environment variables to build ProxyConfig.

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SNIHostName;
import javax.net.ssl.SNIServerName;
Copy link

Copilot AI Oct 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import SNIServerName is unused in this file; remove it to reduce noise and keep imports minimal.

Suggested change
import javax.net.ssl.SNIServerName;

Copilot uses AI. Check for mistakes.

private final int statusCode;
private final HttpHeaders headers;
private final HttpURLConnection connection;
private byte[] cachedRequestBodyBytes;
Copy link

Copilot AI Oct 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The field name cachedRequestBodyBytes is misleading because it stores the response body; rename to cachedResponseBodyBytes for clarity and consistency with its usage in getBodyAsByteArray().

Copilot generated this review using guidance from repository custom instructions.

return headers;
}

public int extractStatusCode(HttpURLConnection connection) {
Copy link

Copilot AI Oct 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helper method is only used internally and doesn't need to be public; change its visibility to private to narrow the API surface.

Suggested change
public int extractStatusCode(HttpURLConnection connection) {
private int extractStatusCode(HttpURLConnection connection) {

Copilot uses AI. Check for mistakes.

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.MalformedParametersException;
Copy link

Copilot AI Oct 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MalformedParametersException (from java.lang.reflect) is unrelated here and never thrown; remove the import and the throws clause (or replace with MalformedURLException if actually needed) to prevent confusion and inaccurate exception signaling.

Suggested change
import java.lang.reflect.MalformedParametersException;

Copilot uses AI. Check for mistakes.

}


private URL rewriteTokenRequestForProxy(URL originalUrl) throws MalformedParametersException{
Copy link

Copilot AI Oct 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MalformedParametersException (from java.lang.reflect) is unrelated here and never thrown; remove the import and the throws clause (or replace with MalformedURLException if actually needed) to prevent confusion and inaccurate exception signaling.

Copilot uses AI. Check for mistakes.

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.MalformedParametersException;
import java.lang.reflect.Proxy;
Copy link

Copilot AI Oct 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import java.lang.reflect.Proxy is unused; remove it to keep imports clean.

Suggested change
import java.lang.reflect.Proxy;

Copilot uses AI. Check for mistakes.

connection.setRequestMethod(request.getHttpMethod().toString());
// connection.setConnectTimeout(10_000);
// connection.setReadTimeout(20_000);
connection.setDoOutput(true);
Copy link

Copilot AI Oct 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setDoOutput(true) is applied unconditionally; restrict this to methods that actually send a body (e.g., POST/PUT/PATCH) to avoid unintended semantics on GET/DELETE requests.

Suggested change
connection.setDoOutput(true);
// Only set doOutput for methods that support a body
String method = request.getHttpMethod().toString();
if ("POST".equalsIgnoreCase(method) || "PUT".equalsIgnoreCase(method) || "PATCH".equalsIgnoreCase(method)) {
connection.setDoOutput(true);
}

Copilot uses AI. Check for mistakes.

if (request.getBodyAsBinaryData() != null) {
byte[] bytes = request.getBodyAsBinaryData().toBytes();
if (bytes != null && bytes.length > 0) {
connection.getOutputStream().write(bytes);
Copy link

Copilot AI Oct 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output stream is not closed or flushed, leading to a potential resource leak; wrap the write in a try-with-resources: try (OutputStream os = connection.getOutputStream()) { os.write(bytes); }.

Suggested change
connection.getOutputStream().write(bytes);
try (java.io.OutputStream os = connection.getOutputStream()) {
os.write(bytes);
}

Copilot uses AI. Check for mistakes.


private SSLContext getSSLContext() {
try {
// If no CA override provide, use default
Copy link

Copilot AI Oct 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected wording from 'provide' to 'provided'.

Suggested change
// If no CA override provide, use default
// If no CA override provided, use default

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

1 participant